package com.harkjeans.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

/**
 * ClassName: JDBCdemo
 * Package: com.harkjeans.jdbc
 * Description:
 *
 * @Author harkjeans
 * @Create 2025/9/12 18:41
 * @Version 1.0
 */
public class JDBCDemo {

    public static void main(String[] args) throws Exception {
        //注册驱动
        Class.forName("com.mysql.jdbc.Driver");

        //获取链接
        String url = "jdbc:mysql://127.0.0.1:3306/dbtest1?useSSL=false";
        String username = "root";
        String password = "pcq123456";
        Connection conn = DriverManager.getConnection(url, username, password);

        //定义sql
        String sql = "update tabletest1 set money = 5000 where id = 1";

        //获取执行sql的对象 Statement
        Statement stmt = conn.createStatement();

        //执行sql
        int count = stmt.executeUpdate(sql);//受影响行数

        //处理结果
        System.out.println(count);

        //释放资源
        stmt.close();
        conn.close();
    }
}
